package com.caigou.util;


import com.caigou.enums.ResponseEnum;
import org.springframework.validation.BindingResult;

public class ResultUtil {
    /**
     * 成功
     * */
    public static Result success(Object object){
        Result result = new Result();
        result.setStatus(200);//200为成功
        result.setMessage("请求成功");
        result.setData(object);
        return result;
    }
    
    public static Result success(Object object, String msg){
        Result result = new Result();
        result.setStatus(200);//200为成功
        result.setMessage(msg);
        result.setData(object);
        return result;
    }
	/**
	 * 失败，自定义错误
	 * */
    public static Result error(Integer status, String msg){
        Result result = new Result();
        result.setStatus(status);//500为成功
        result.setMessage(msg);
        return result;
    }
    /**
     * 无权限访问
     * */
    public static Result noAuthority(String msg){
        Result result = new Result();
        result.setStatus(403);//500为成功
        result.setMessage(msg);
        return result;
    }

    public static Result error(ResponseEnum paramError, BindingResult bindingResult) {
        Result result = new Result();
        result.setStatus(paramError.getCode());//500服务器内部错误
        result.setMessage(bindingResult.getFieldError().getDefaultMessage());
        return result;
    }

    public static Result error(ResponseEnum paramError) {
        Result result = new Result();
        result.setStatus(paramError.getCode());
        result.setMessage(paramError.getMessage());
        return result;
    }

    public static Result wrongParam(String msg) {
        Result result = new Result();
        result.setStatus(400);//400参数错误
        result.setMessage(msg);
        return result;
    }

    public static Result error(String msg) {
        Result result = new Result();
        result.setStatus(400);//400参数错误
        result.setMessage(msg);
        return result;
    }




//    public static Result getDicResult(Map<Integer, String> dicMap) {
//        if (!dicMap.isEmpty()) {
//            List<KeyValueVO> valueVOS = dicMap.entrySet().stream().sorted(Comparator.comparing(Map.Entry::getKey))
//                    .map(dic -> new KeyValueVO(dic.getKey(), dic.getValue()))
//                    .collect(Collectors.toList());
//            return ResultUtil.success(valueVOS);
//        }
//        return ResultUtil.error("未查询到类型");
//    }
//
//    public static Result getRegionResult(Map<String, String> dicMap) {
//        if (!dicMap.isEmpty()) {
//            List<KeyValueVO> valueVOS = dicMap.entrySet().stream().sorted(Comparator.comparing(Map.Entry::getKey))
//                    .map(dic -> new KeyValueVO(dic.getKey(), dic.getValue()))
//                    .collect(Collectors.toList());
//            return ResultUtil.success(valueVOS);
//        }
//        return ResultUtil.error("未查询到类型");
//    }

}
